package com.zhiliao.prototype.demo1;

import java.util.ArrayList;
import java.util.List;

/**
 * 作者： zhi-liao
 * 类的作用:
 * 类的创建时间： 2021/5/23 14:51
 */
public class Cat implements Cloneable {

    private String name;
    private ArrayList<String> list = new ArrayList<>();
    public Cat() {
        System.out.println("invoke cat constrctor");
    }

    public void setName(String name) {
        this.name = name;
    }

    public ArrayList<String> getList() {
        return list;
    }

    public void setList(ArrayList<String> list) {
        this.list = list;
    }

    public String getName() {
        return name;
    }

    public Cat clone() {
        Cat cat = null;
        try {
            cat = (Cat) super.clone();
            // list集合需要自己手动深拷贝
            cat.list = (ArrayList<String>) this.list.clone();
        }catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return cat;
    }
}
